<?php
include_once('admin_global.php');
bn_include_lib('bn_jquery');
$theme->add_block('body');
$mnu=new bn_menu;

if(isset($_POST['cmd']))
{
    extract($_POST);
    if($cmd=='type')
         die($mnu->treemenu($type));
    if($cmd=='submit')
    {
        if($menuctrl1_id=='')
        $mnu->insert(0,$menuddl,$name,$url,$descr);
        else
        $mnu->update($name,$url,$descr,$menuctrl1_id);
        die($mnu->treemenu($menuddl));
    }
    
    if($cmd=='delete')
    {
        $mnu->delete($menuctrl1_id);
        die($mnu->treemenu($menuddl));
    }
    
    if($cmd=='submenu')
    {
        if($menuctrl1_id!='')
        $mnu->insert($menuctrl1_id,$menuddl,$name,$url,$descr);
        die($mnu->treemenu($menuddl)); 
    }

}
$theme->add_script(jquery_submit_show('#submit','submit','#menu_tbl'));
$theme->add_script(jquery_submit_show('#del','delete','#menu_tbl'));
$theme->add_script(jquery_submit_show('#submenu','submenu','#menu_tbl'));
?>
<script>
$('#menuddl').live('change',function(){
    $.post(window.location.href,{cmd:'type',type:$(this).val()},function(data){
     $('#show').html(data);   
    });
});

$('#menuctrl1 a').live('click',function(e){
    e.preventDefault();
});
</script>
<table id="menu_tbl">
<tr>
	<td><?= $lang[36] ?></td>
	<td><?= $mnu->ddl_menutype(); ?></td>
</tr>
<tr>
	<td colspan="2"><div id="show"><?= $mnu->treemenu('user1'); ?></div></td>
</tr>
<tr>
	<td><?= $lang[37] ?></td>
	<td><input type="text" size="36" autocomplete="on" name="name" id="name" class="input-text"/></td>
</tr>
<tr>
	<td><?= $lang[38] ?></td>
	<td><textarea cols="32"wrap="virtual" maxlength="100" name="descr" id="descr" class="input-text"></textarea></td>
</tr>
<tr>
    <td><?= $lang[39] ?></td>
    <td>
    <input type="text" size="70" name="url" id="url" class="input-text"/>
    </td>
</tr>
<tr>
	<td colspan="2">
    <input type="submit" name="submit" id="submit" value="<?= $lang[15] ?>" class="button"/>
    <input type="submit" name="submenu" id="submenu" value="<?= $lang[40] ?>" class="button"/>
    <input type="submit" name="del" id="del" value="<?= $lang[11] ?>" class="button red"/>
    </td>
</tr>
</table>
<?php
$theme->render();
?>